package com.huawei.java.main.classes;

public class Request {
    final boolean add;
    final String serviceType;
    final int serviceId;

    public Request(boolean add, String vmType, int vmId) {
        this.add = add;
        this.serviceType = vmType;
        this.serviceId = vmId;
    }

    public Request(String describe) {
        final String substring = describe.substring(1, describe.length() - 1);
        final String[] parts = substring.split("\\s*,\\s*");
        this.add = parts[0].equals("add");
        if (this.add) {
            this.serviceType = parts[1];
            this.serviceId = Integer.parseInt(parts[2]);
        } else {
            this.serviceType = null;
            this.serviceId = Integer.parseInt(parts[1]);
        }

    }

    public boolean isAdd() {
        return add;
    }

    public String getServiceType() {
        return serviceType;
    }

    public int getServiceId() {
        return serviceId;
    }
}
